using System.Collections;
using QFramework.Framework.ResKit;
using UnityEditor;
using UnityEngine;

namespace QFramework.Example._10.ResMgrExample
{
    public class ResMgrExample : MonoBehaviour
    {
        private readonly ResLoader _resLoader = new();

        private IEnumerator Start()
        {
            yield return new WaitForSeconds(2.0f);

            _resLoader.LoadAsync<AudioClip>("resources://Hit", hitClip =>
            {
                Debug.Log(hitClip.name);
                Debug.Log(Time.time);
            });
            Debug.Log(Time.time);

            yield return new WaitForSeconds(2.0f);

            _resLoader.LoadSync<AudioClip>("resources://Start");

            yield return new WaitForSeconds(2.0f);

            _resLoader.LoadSync<AudioClip>("resources://Audio/Hit");

            _resLoader.LoadSync<GameObject>("resources://HomePanel");

            yield return new WaitForSeconds(5.0f);

            _resLoader.ReleaseAll();
        }

#if UNITY_EDITOR
        [MenuItem("QFramework/Example/10.ResMgrExample", false, 10)]
        private static void MenuClicked()
        {
            EditorApplication.isPlaying = true;

            new GameObject("ResMgrExample").AddComponent<ResMgrExample>();
        }
#endif
    }
}